const api = require("../api.js");
//获取应用实例
const {network} = getApp();

Page({
  data: {
    name: "",
    account: "",
    bank: "",
    array: ['招商银行',
      '工商银行',
      '农业银行',
      '中国银行',
      '建设银行',
      '交通银行',
      '平安银行',
      '民生银行',
      '兴业银行',
      '中信银行','光大银行','华夏银行','浦发银行','广发银行','北京银行'],
    activeBlank: '',
    money: 0,
    amount: 0
  },
  onLoad(e) {
    this.setData({
      amount: e.amount
    });
    console.log(e);
  },
  onShow() {
    // wx.navigateToMiniProgram({
    //   appId: 'wx3725ea3e47d7a7e3',
    //   path: `/pages/home/main/index`
    // });
  },
  bindblurName(e) {
    this.data.name = e.detail.value;
  },
  bindblurAccount(e) {
    this.data.account = e.detail.value;
  },
  bindblurBank(e) {
    this.data.bank = e.detail.value;
  },
  bindBlurMoney(e) {
    this.data.money = e.detail.value;
  },
  toGetApply() {
    console.log(this.data.name);
    console.log(this.data.account);
    console.log(this.data.money);
    console.log(this.data.activeBlank);
    if (parseFloat(this.data.money) < 0) {
      wx.showToast({
        title: '提现金额不能小于零',
        icon: 'none'
      });
      return false;
    }
    if (parseFloat(this.data.money) == 0) {
      wx.showToast({
        title: '提现金额不能等于零',
        icon: 'none'
      });
      return false;
    }
    if (parseFloat(this.data.money) > parseFloat(this.data.amount)) {
      wx.showToast({
        title: '提现金额不能大于账户余额',
        icon: 'none'
      });
      return false;
    }
    if (!this.data.name) {
      wx.showToast({
        title: '请填写户名',
        icon: 'none'
      });
      return false;
    }
    if (!this.data.account) {
      wx.showToast({
        title: '请填写银行卡号',
        icon: 'none'
      });
      return false;
    }
    if (!this.data.activeBlank) {
      wx.showToast({
        title: '请选择银行',
        icon: 'none'
      });
      return false;
    }
    network.post(api.NewOrderWithdrawals, {
      EncTrueName: this.data.name,
      EncBankNo: this.data.account,
      BankCode: this.data.activeBlank,
      Amount: this.data.money
    }).then((data) => {
      console.log(data);
      wx.redirectTo({url: '/pages/home/main/index'});
    }, (data) => {
      console.log(data, 'errrrrrrrrrrrrrrr');
    });
  },
  bindPickerChange(e) {
    this.setData({
      activeBlank: this.data.array[e.detail.value]
    })
  }
});
